#include <wx/frame.h>
#include <wx/listctrl.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/stattext.h>
#include <wx/checkbox.h>
#include <wx/spinctrl.h>
#include <wx/msgdlg.h>
#include <wx/filepicker.h>
#include <wx/progdlg.h>
#include "ImageDisplay.h"
#include "ServerManage.h"

class MainFrame : public wxFrame
{
public:
    MainFrame();
    //virtual ~MainFrame();
private:
    wxButton* btnInitDevice;  //这一步包含刷新相机列表，自动连接相机，自动打开相机
    wxButton* btnStartShot;
    wxButton* btnStartSave;
    wxButton* btnGetDeviceStatus;
    wxButton* btnFileTransfer;
    wxStaticText* txtInf;
    ImageDisplay* displayArea;
    wxListCtrl* deviceList;
    wxCheckBox* chkCameraTrigger;
    wxCheckBox* chkControlAll; //用于控制所有相机
    wxSpinCtrl* spinImageHeight;
    wxSpinCtrl* spinImageWidth;
    wxSpinCtrl* spinImageXOffset;
    wxSpinCtrl* spinImageYOffset;
    wxSpinCtrl* spinExposureTime;
    wxSpinCtrl* spinFrameControl;
    wxButton* btnGetCameraPara;
    wxDirPickerCtrl* dirFileSavePath;
    std::unique_ptr<ServerManage> serverManage;
    std::string fileSavePath;
    std::unique_ptr<wxProgressDialog> progDlg;

    void on_btnInitDevice_click(wxCommandEvent& event);
    void on_btnGetDeviceStatus_click(wxCommandEvent& event);
    void on_btnStartShot_click(wxCommandEvent& event);
    void on_btnStartSave_click(wxCommandEvent& event);
    void on_deviceList_deselect(wxListEvent& event);
    void on_deviceList_select(wxListEvent& event);
    void on_serverConn_new(ServerConnEvent& event);
    void on_serverConn_close(ServerConnEvent& event);
    void on_server_newImage(NewImageData& event);
    void on_device_message(DeviceMessageEvent& event);
    void on_spinImageHeight_change(wxSpinEvent& event);
    void on_spinImageWidth_change(wxSpinEvent& event);
    void on_spinImageXOffset_change(wxSpinEvent& event);
    void on_spinImageYOffset_change(wxSpinEvent& event);
    void on_spinExposureTime_change(wxSpinEvent& event);
    void on_spinFrameControl_change(wxSpinEvent& event);
    void on_chkCameraTrigger_click(wxCommandEvent& event);
    void on_btnGetCameraPara_click(wxCommandEvent& event);
    void on_dirFileSavePath_change(wxFileDirPickerEvent& event);
    void on_btnFileTransfer_click(wxCommandEvent& event);
    void on_chkControlAll_change(wxCommandEvent& event);

    void on_transferFileStart(ReceiveNewEvent& event);
    void on_transferFileStop(wxCommandEvent& event);
    void on_transferFileNewBlock(ReceiveNewEvent& event);

    void updateUI(DeviceStatus deviceStatus);
    void SetCameraControlEnable(bool enable);
};

enum class MainFrameID : int
{
    btnInitDevice,
    btnStartShot,
    btnStartSave,
    displayArea,
    deviceList,
    txtInf,
    btnGetDeviceStatus,
    chkCameraTrigger,
    spinImageHeight,
    spinImageWidth,
    spinImageXOffset,
    spinImageYOffset,
    spinExposureTime,
    spinFrameControl,
    btnGetCameraPara,
    dirFileSavePath,
    btnFileTransfer,
    chkControlAll
};
